﻿using Ewell.Interface.Common.Model.Common;
using Ewell.Interface.Common.Model.GateWay;
using System.Windows;

namespace Ewell.Interface.Common.Utils
{
    public static class GateWayResultExtend
    {
        /// <summary>
        /// 检查是否成功
        /// </summary>
        /// <param name="gateWayResult"></param>
        /// <returns></returns>
        public static GateWayResult<T> CheckSuccess<T>(this GateWayResult<T> gateWayResult)
        {
            if (!gateWayResult.success) throw new SpeedException(gateWayResult.message);
            return gateWayResult;
        }
        /// <summary>
        /// 检查是否成功
        /// </summary>
        /// <param name="gateWayResult"></param>
        /// <returns></returns>
        public static GateWayResult<T> CheckSuccess<T>(this GateWayResult<T> gateWayResult, string messageHeader)
        {
            if (!gateWayResult.success) throw new SpeedException(messageHeader, gateWayResult.message);
            return gateWayResult;
        }
        /// <summary>
        /// 检查警告信息
        /// </summary>
        /// <param name="gateWayResult"></param>
        /// <returns></returns>
        public static GateWayResult<T> CheckWarning<T>(this GateWayResult<T> gateWayResult)
        {
            if (gateWayResult.hasWarning)
                MessageBox.Show(gateWayResult.message);
            return gateWayResult;
        }
        /// <summary>
        /// 检查结果状态
        /// </summary>
        /// <param name="gateWayResult"></param>
        /// <returns></returns>
        public static GateWayResult<T> CheckState<T>(this GateWayResult<T> gateWayResult)
        {
            CheckSuccess(gateWayResult);
            return CheckWarning(gateWayResult);
        }
        /// <summary>
        /// 检查结果状态
        /// </summary>
        /// <param name="gateWayResult"></param>
        /// <returns></returns>
        public static GateWayResult<T> CheckState<T>(this GateWayResult<T> gateWayResult, string messageHeader)
        {
            CheckSuccess(gateWayResult, messageHeader);
            return CheckWarning(gateWayResult);
        }
    }
}
